package com.springcloud.config.feign;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import com.springcloud.entity.UserEntity;

@FeignClient(value = "microservice-provider-user", fallback = UserClientHystrixFallback.class)
public interface UserClient {

	// @RequestMapping(method = RequestMethod.GET, value = "/get/{id}")
	@GetMapping("/get/{id}")
	UserEntity get(@PathVariable("id") long id);

	// @RequestMapping(method = RequestMethod.POST, value = "/post/{id}")
	@PostMapping("/post/{id}")
	UserEntity post(@PathVariable("id") long id);
}

@Component
class UserClientHystrixFallback implements UserClient {

	@Override
	public UserEntity get(long id) {
		System.err.println("this is HystrixFallback");
		UserEntity userEntity = new UserEntity();
		userEntity.setId(111l);
		return userEntity;
	}

	@Override
	public UserEntity post(long id) {
		System.err.println("this is HystrixFallback");
		UserEntity userEntity = new UserEntity();
		userEntity.setId(222l);
		return userEntity;
	}
}
